package com.hgb.mall.admin.dao;


import com.hgb.mall.mbg.entity.UmsAdminRoleRelation;
import com.hgb.mall.mbg.entity.UmsResource;
import com.hgb.mall.mbg.entity.UmsRole;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;

import java.util.List;

/**
 * 自定义后台用户与角色管理Dao
 * Created by hgb on 2020/10/8.
 */
public interface UmsAdminRoleRelationDao {
    /**
     * 批量插入用户角色关系
     */
    int insertList(@Param("list") List<UmsAdminRoleRelation> adminRoleRelationList);

    /**
     * 获取用户所有角色
     */
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "RoleListResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "admin_count", jdbcType = JdbcType.INTEGER, property = "adminCount"),
            @Result(column = "create_time", jdbcType = JdbcType.TIMESTAMP, property = "createTime"),
            @Result(column = "status", jdbcType = JdbcType.INTEGER, property = "status"),
            @Result(column = "sort", jdbcType = JdbcType.INTEGER, property = "sort")
    })
    List<UmsRole> getRoleList(SelectStatementProvider selectStatement);

    /**
     * 获取用户所有可访问资源
     */
    List<UmsResource> getResourceList(@Param("adminId") Long adminId);

    /**
     * 获取资源相关用户ID列表
     */
    List<Long> getAdminIdList(@Param("resourceId") Long resourceId);
}
